$(function(){
//搜索
$('#search input').focus(function(){
$(this).parents('#search').addClass('search_focus');
})
$('#search input').blur(function(){
$(this).parents('#search').removeClass('search_focus');
})
$('.searchTb input').focus(function(){
$(this).parents('.searchTb').addClass('search_focus');
})
$('.searchTb input').blur(function(){
$(this).parents('.searchTb').removeClass('search_focus');
})
//快递查询
$('.se_kuaidi .kd_in input').focus(function(){
$(this).parents('.kd_in').addClass('search_focus');
})
$('.se_kuaidi .kd_in input').blur(function(){
$(this).parents('.kd_in').removeClass('search_focus');
})
$('.se_kuaidi').hover(function(){$(this).children('.kdcx').stop().show();$(this).children('span').addClass('on');},function(){$(this).children('.kdcx').stop().hide();$(this).children('span').removeClass('on');})



//业务
/*var timer=null;
$('#business li').hover(function(){
$('#business li').css('opacity','0.5');
$(this).css({"opacity":"1","boxShadow":"0 0 6px #b0b0b0"});
clearTimeout(timer);
},function(){timer=setTimeout(function(){$('#business li').css({"opacity":"","boxShadow":""});},400);
})
*/



//app下载
$('.app_down').hover(function(){
	$(this).css({"backgroundColor":"#fff","borderColor":"#ddd"});
	$(this).find('.app_info').show();
},function(){
	$(this).css({"backgroundColor":"","borderColor":""});
	$(this).find('.app_info').hide();
})



//animate_bg();



//返回顶部部
var offset_roll = 200,
	offset_head = 200,
	scroll_top_duration = 200,
	$back_to_top = $('#returnTop');

$(window).scroll(function(){
	( $(this).scrollTop() > offset_roll ) ? $back_to_top.css({"display":"block","opacity":"1"}) : $back_to_top.css({"display":"none","opacity":"0"});
});

$back_to_top.on('click', function(event){
	event.preventDefault();
	$('body,html').animate({
		scrollTop: 0 ,
		}, scroll_top_duration
	);
});




})



//主背景
/*
function animate_bg(){
var oAnimate = $('#animate');
var oBg = ['images/bg1.jpg','images/bg2.jpg','images/bg3.jpg','images/bg4.jpg']
var timer1 = timer2 = null;
oAnimate.append('<img class=b1 src='+oBg[0]+' /><img class=b2 src='+oBg[1]+' />');
$('.b1').css({"position":"absolute","width":"100%","height":"100%","zIndex":"0","top":"0","left":"0"})
$('.b2').css({"position":"absolute","width":"100%","height":"100%","zIndex":"0","top":"0","left":"0"})
i = 0;
j = 1;
timer1=setInterval(function(){
	$('.b1').attr('src',oBg[i]);
	$('.b1').show()?$('.b1').fadeOut(2000):$('.b1').fadeIn(2000);
	i+=2;
	if(i>=oBg.length){
	i=0;
	}
},2000);
timer2=setInterval(function(){
	$('.b2').attr('src',oBg[j]);
	$('.b2').show()?$('.b2').fadeOut(2000):$('.b2').fadeIn(2000);
	j+=2;
	if(j>=oBg.length){
	j=1;
	}
},2000);

}

*/

/*
function animate_bg(){
var oAnimate = $('#animate');
var oBg = ['images/bg1.jpg','images/bg2.jpg','images/bg3.jpg','images/bg4.jpg']
var timer = null;
i=0;
timer=setInterval(function(){
	oAnimate.css('backgroundImage','url("'+oBg[i]+'")');
	i++;
	if(i==oBg.length){
	i=0;
	}
},2000);
}
*/




window.onload=function(){

//banner
var sWidth = $("#focus").width(); //获取焦点图的宽度（显示面积）
var len = $("#focus ul li").length; //获取焦点图个数
var index = 0;
var picTimer;

//以下代码添加数字按钮和按钮后的半透明条，还有上一页、下一页两个按钮
var btn = "<div class='btnBg'></div><div class='btn'>";
for(var i=0; i < len; i++) {
	btn += "<span></span>";
}
btn += "</div><div class='preNext pre'></div><div class='preNext next'></div>";
$("#focus").append(btn);
$("#focus .btnBg").css("opacity",0.5);

//为小按钮添加鼠标滑入事件，以显示相应的内容
$("#focus .btn span").css("opacity",0.4).mouseenter(function() {
	index = $("#focus .btn span").index(this);
	showPics(index);
}).eq(0).trigger("mouseenter");

//上一页、下一页按钮透明度处理
$("#focus .preNext").css("opacity",0.2).hover(function() {
	$(this).stop(true,false).animate({"opacity":"0.5"},300);
},function() {
	$(this).stop(true,false).animate({"opacity":"0.2"},300);
});

//上一页按钮
$("#focus .pre").click(function() {
	index -= 1;
	if(index == -1) {index = len - 1;}
	showPics(index);
});

//下一页按钮
$("#focus .next").click(function() {
	index += 1;
	if(index == len) {index = 0;}
	showPics(index);
});

//本例为左右滚动，即所有li元素都是在同一排向左浮动，所以这里需要计算出外围ul元素的宽度
$("#focus ul").css("width",sWidth * (len));

//鼠标滑上焦点图时停止自动播放，滑出时开始自动播放
$("#focus").hover(function() {
	clearInterval(picTimer);
},function() {
	picTimer = setInterval(function() {
		showPics(index);
		index++;
		if(index == len) {index = 0;}
	},4000); //此4000代表自动播放的间隔，单位：毫秒
}).trigger("mouseleave");

//显示图片函数，根据接收的index值显示相应的内容
function showPics(index) { //普通切换
	var nowLeft = -index*sWidth; //根据index值计算ul元素的left值
	$("#focus ul").stop(true,false).animate({"left":nowLeft},300); //通过animate()调整ul元素滚动到计算出的position
	//$("#focus .btn span").removeClass("on").eq(index).addClass("on"); //为当前的按钮切换到选中的效果
	$("#focus .btn span").stop(true,false).animate({"opacity":"0.4"},300).eq(index).stop(true,false).animate({"opacity":"1"},300); //为当前的按钮切换到选中的效果
}



//多余宽度（换行问题）
$('.business').width($('#business').width()+100);

}







//搜索
function showForm(a,b){
	$('.se_in').hide();
	$('#'+a).show();
	$('.searchBar span').removeClass('on');
	$('#'+b).addClass('on');	
}

//收藏我们
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}